package com.youlu.campus.service.activity.impl;

import com.youlu.campus.base.base.EntityBase;
import com.youlu.campus.entity.ActivityBlackList;
import com.youlu.campus.service.activity.ActivityBlackListService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class ActivityBlackListServiceImpl implements ActivityBlackListService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public boolean inBlackList(String mobile, String activityId) {
        log.info(":>>> 开始判断用户是否在黑名单中:{},{}", mobile, activityId);
        if (StringUtils.isBlank(mobile) || StringUtils.isBlank(activityId)) {
            log.error(":>>> 电话或活动ID为空");
            return false;
        }
        Query query = new Query();
        query.addCriteria(Criteria.where("mobile").is(mobile).and("activityId").is(activityId));
        boolean exist = mongoTemplate.exists(query, ActivityBlackList.class);
        log.info(":>>> 用户:{},是否在活动:{} 黑名单:{} ", mobile, activityId, exist);
        return exist;
    }
}
